<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>17-Promise-API-Promise的all和race方法</h1>
    <script>

        // 练习：创建多个Promise对象，并使用all来进行检测

        const p1 = Promise.resolve("ok1");
        const p2 = Promise.resolve(Promise.resolve("ok2"));
        const p3 = Promise.resolve(Promise.reject("error3"));
        const p4 = Promise.reject("error4");
        const p5 = new Promise((resolve, reject) => {
            
            setTimeout(() => {
                reject("error5");
            }, 100);
        })

        //console.log(p1,p2,p3,p4);

        const pAll = Promise.all([p1, p4, p2, p3]);

        pAll.then(value =>{
            console.log("成功信息", value);
        },reason => {
            console.log("失败信息", reason);
        });

        // 寻找第一个成功的并返回
        const pAll2 = Promise.race([p5, p3, p2]);

        pAll2.then(value =>{
            console.log("成功信息", value);
        },reason => {
            console.log("失败信息", reason);
        });


    </script>
</body>
</html>